
package example

import (
	"context"
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/example"
    exampleReq "github.com/flipped-aurora/gin-vue-admin/server/model/example/request"
)

type SysUsersService struct {}
// CreateSysUsers 创建sysUsers表记录
// Author [yourname](https://github.com/yourname)
func (sysUsersService *SysUsersService) CreateSysUsers(ctx context.Context, sysUsers *example.SysUsers) (err error) {
	err = global.GVA_DB.Create(sysUsers).Error
	return err
}

// DeleteSysUsers 删除sysUsers表记录
// Author [yourname](https://github.com/yourname)
func (sysUsersService *SysUsersService)DeleteSysUsers(ctx context.Context, id string) (err error) {
	err = global.GVA_DB.Delete(&example.SysUsers{},"id = ?",id).Error
	return err
}

// DeleteSysUsersByIds 批量删除sysUsers表记录
// Author [yourname](https://github.com/yourname)
func (sysUsersService *SysUsersService)DeleteSysUsersByIds(ctx context.Context, ids []string) (err error) {
	err = global.GVA_DB.Delete(&[]example.SysUsers{},"id in ?",ids).Error
	return err
}

// UpdateSysUsers 更新sysUsers表记录
// Author [yourname](https://github.com/yourname)
func (sysUsersService *SysUsersService)UpdateSysUsers(ctx context.Context, sysUsers example.SysUsers) (err error) {
	err = global.GVA_DB.Model(&example.SysUsers{}).Where("id = ?",sysUsers.Id).Updates(&sysUsers).Error
	return err
}

// GetSysUsers 根据id获取sysUsers表记录
// Author [yourname](https://github.com/yourname)
func (sysUsersService *SysUsersService)GetSysUsers(ctx context.Context, id string) (sysUsers example.SysUsers, err error) {
	err = global.GVA_DB.Where("id = ?", id).First(&sysUsers).Error
	return
}
// GetSysUsersInfoList 分页获取sysUsers表记录
// Author [yourname](https://github.com/yourname)
func (sysUsersService *SysUsersService)GetSysUsersInfoList(ctx context.Context, info exampleReq.SysUsersSearch) (list []example.SysUsers, total int64, err error) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&example.SysUsers{})
    var sysUserss []example.SysUsers
    // 如果有条件搜索 下方会自动创建搜索语句
	err = db.Count(&total).Error
	if err!=nil {
    	return
    }

	if limit != 0 {
       db = db.Limit(limit).Offset(offset)
    }

	err = db.Find(&sysUserss).Error
	return  sysUserss, total, err
}
func (sysUsersService *SysUsersService)GetSysUsersPublic(ctx context.Context) {
    // 此方法为获取数据源定义的数据
    // 请自行实现
}
